package com.qianfeng.dbsm.impl;


import com.qianfeng.dbsm.dao.TbProductDistributionDao;
import com.qianfeng.dbsm.entity.TbProductCosmetics;
import com.qianfeng.dbsm.entity.TbProductDistribution;
import com.qianfeng.dbsm.service.TbProductDistributionService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商家商品分销层(TbProductDistribution)表服务实现类
 *
 * @author makejava
 * @since 2022-11-17 17:17:31
 */
@Service("tbProductDistributionService")
public class TbProductDistributionServiceImpl implements TbProductDistributionService {
    @Resource
    private TbProductDistributionDao tbProductDistributionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param tbProductDistributionId 主键
     * @return 实例对象
     */
    @Override
    public TbProductDistribution queryById(Integer tbProductDistributionId) {
        return this.tbProductDistributionDao.queryById(tbProductDistributionId);
    }

    /**
     * 分页查询
     *
     * @param tbProductDistribution 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbProductDistribution> queryByPage(TbProductDistribution tbProductDistribution, PageRequest pageRequest) {
        long total = this.tbProductDistributionDao.count(tbProductDistribution);
        //return new PageImpl<>(this.tbProductDistributionDao.queryAllByLimit(tbProductDistribution, pageRequest), pageRequest, total);
        return null;
    }

    /**
     * 新增数据
     *
     * @param tbProductDistribution 实例对象
     * @return 实例对象
     */
    @Override
    public TbProductDistribution insert(TbProductDistribution tbProductDistribution) {
        this.tbProductDistributionDao.insert(tbProductDistribution);
        return tbProductDistribution;
    }

    /**
     * 修改数据
     *
     * @param tbProductDistribution 实例对象
     * @return 实例对象
     */
    @Override
    public TbProductDistribution update(TbProductDistribution tbProductDistribution) {
        this.tbProductDistributionDao.update(tbProductDistribution);
        return this.queryById(tbProductDistribution.getTbProductDistributionId());
    }

    /**
     * 通过主键删除数据
     *
     * @param tbProductDistributionId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer tbProductDistributionId) {
        return this.tbProductDistributionDao.deleteById(tbProductDistributionId) > 0;
    }

    @Override
    public List<TbProductDistribution> queryByProductAndUser(int productId,int memberId) {
        return this.tbProductDistributionDao.queryByProductAndUser(productId,memberId);
    }
}
